package golf.simulation.dataobject;

import java.sql.Date;

public class Transaction {
	
	private TransactionType transactionType;
	private double buyPrice;
	private double sellPrice;
	private Date buyDate;
	private Date sellDate;
	
	private double sellLimit;
	private double cutLimit;
	private double pillowLimit;
	
	private double pillowPercentage;
	private double sellPercentage;
	
	private boolean pillowIsThere;
	
	private double profitLoss;
	
	public String toString(){
		StringBuffer out = new StringBuffer();
		
		out.append(transactionType);
		out.append(";");

		out.append(buyDate.toString());
		out.append(";");
		
		out.append(buyPrice);
		out.append(";");
		
		out.append(sellDate == null? "" : sellDate.toString());
		out.append(";");
		
		out.append(sellPrice);
		out.append(";");
		
		out.append(sellLimit);
		out.append(";");
		
		out.append(cutLimit);
		out.append(";");
		
		out.append(pillowLimit);
		out.append(";");
		
		out.append(profitLoss);

		return out.toString();
	}
	
	public Transaction(TransactionType _transactionType, double _pillowPercentage, double _sellPercentage){
		pillowPercentage = _pillowPercentage;
		sellPercentage = _sellPercentage;
		transactionType = _transactionType;
		pillowIsThere = true;
	}
	
	public double getProfitOrLoss(){
		if(transactionType.equals(TransactionType.LONG)){
			return (sellPrice - buyPrice) * 1000;
		}else{
			return (buyPrice - sellPrice) * 1000;
		}
	}
	
	public TransactionType getTransactionType() {
		return transactionType;
	}
	public void setTransactionType(TransactionType transactionType) {
		this.transactionType = transactionType;
	}
	public double getBuyPrice() {
		return buyPrice;
	}
	public void setBuyPrice(double buyPrice) {
		this.buyPrice = buyPrice;
		
		if(pillowPercentage > 0){
			if(transactionType.equals(TransactionType.LONG)){
				pillowLimit = this.buyPrice + (this.buyPrice * this.pillowPercentage);
				cutLimit = this.buyPrice - (this.buyPrice * this.pillowPercentage);
			}else if(transactionType.equals(TransactionType.SHORT)){
				pillowLimit = this.buyPrice - (this.buyPrice * this.pillowPercentage);
				cutLimit = this.buyPrice + (this.buyPrice * this.pillowPercentage);
			}
		}

		if(sellPercentage > 0){
			if(transactionType.equals(TransactionType.LONG)){
				sellLimit = this.buyPrice + (this.buyPrice * this.sellPercentage);
			}else if(transactionType.equals(TransactionType.SHORT)){
				sellLimit = this.buyPrice - (this.buyPrice * this.sellPercentage);
			}
		}

	}
	public double getSellPrice() {
		return sellPrice;
	}
	public void setSellPrice(double sellPrice) {
		this.sellPrice = sellPrice;
	}
	public Date getBuyDate() {
		return buyDate;
	}
	public void setBuyDate(Date buyDate) {
		this.buyDate = buyDate;
	}
	public Date getSellDate() {
		return sellDate;
	}
	public void setSellDate(Date sellDate) {
		this.sellDate = sellDate;
	}

	public double getSellLimit() {
		return sellLimit;
	}

	public void setSellLimit(double sellLimit) {
		this.sellLimit = sellLimit;
	}

	public double getCutLimit() {
		return cutLimit;
	}

	public void setCutLimit(double cutLimit) {
		this.cutLimit = cutLimit;
	}

	public double getPillowLimit() {
		return pillowLimit;
	}

	public void setPillowLimit(double pillowLimit) {
		this.pillowLimit = pillowLimit;
	}

	public boolean pillowIsThere() {
		return pillowIsThere;
	}

	public void removePillow() {
		this.pillowIsThere = false;
	}

	public double getProfitLoss() {
		return profitLoss;
	}

	public void setProfitLoss(double profitLoss) {
		this.profitLoss = profitLoss;
	}
}
